package com.wanmait.bootdemo.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wanmait.bootdemo.exception.QuestionTypeNotFoundException;
import com.wanmait.bootdemo.mapper.QuestionTypeMapper;
import com.wanmait.bootdemo.pojo.QuestionType;
import com.wanmait.bootdemo.service.QuestionTypeService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
@Service
@Transactional(rollbackFor = Exception.class)
public class QuestionTypeServiceImpl implements QuestionTypeService {
    private Logger logger = LogManager.getLogger(QuestionTypeServiceImpl.class);

    @Resource
    private QuestionTypeMapper questionTypeMapper;

    @Override
    public void updateSort(Integer id, Integer sort) {

    }

    @Override
    public void increaseQuestionCount(Integer id) {

    }

    @Override
    public void decreaseQuestionCount(Integer id) {

    }

    @Override
    public List<QuestionType> findAll() {
        logger.debug("debug ..................");
        logger.info("info ......................");
        logger.warn("warn .....................");
        logger.error("error ..................");
        logger.fatal("fatal .....................");
        return questionTypeMapper.selectList();
    }

    //一般异常向上抛出机制 当前类的方法如果抛出异常，父类或者接口的方法必须也抛出该异常或者范围更大的异常
    //
    @Override
    public QuestionType findById(Integer id){
        QuestionType questionType = questionTypeMapper.selectOne(id);
        if(questionType == null)
        {
            throw new QuestionTypeNotFoundException(id);
        }
        return questionType;
    }

    @Override
    public int getDataCount() {
        return 0;
    }

    @Override
    public void insert(QuestionType object) {

    }

    @Override
    public void update(QuestionType object) {

    }

    @Override
    public void delete(Integer id) {

    }

    @Override
    public void delete(String ids) {

    }

    @Override
    public PageInfo<QuestionType> findPage(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<QuestionType> questionTypes = questionTypeMapper.selectList();
        PageInfo<QuestionType> pageInfo = new PageInfo<>(questionTypes);
        return pageInfo;
    }
}
